home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <math.h>
- #include <qdoffscreen.h>
- #include <sound.h>
- #include "draw.h"
- #include "async.h"
- #include "hidembar.h"
- #include "score.h"
- #include "health.h"
-
- void InitMac(void);
- void WindowSetup(void);
- void Redraw(void);
- void doEvent(void);
- void SetDrawState(void);
- void SetPlayerState(void);
- void IncreaseScore(void);
- void GameOff(void);
- void GameOn(void);
-
-
- Boolean gDone;
- long lastRedraw;
- long playerOneUpdateTime;
- long playerTwoUpdateTime;
- int drawState;
- Boolean background;
- Boolean soundPlayed;
- char lastCharacter;
- long PlayerOneScore;
- long PlayerTwoScore;
- Boolean gameOn=true;
- Boolean gatesBlood=false;
- Boolean aronBlood=false;
- PicHandle splashScreen;
- Rect gdestrect;
- Boolean splashOn=false;
-
-
- WindowPtr gMainWindow;
-
-
- EventRecord gTheEvent;
-
- main()
- {
- KeyMap keyMap;
- Rect sourceRect;
- Rect destRect;
-
- int eventMask;
- EventRecord theEvent;
- EventRecord bufferEvent;
- int sleep;
- RgnHandle mouseRgn=NewRgn();
- Boolean gotEvent;
-
- sleep = 50;
- eventMask = 78;
-
- InitMac();
- WindowSetup();
- setupGWorld();
-
- pl1info = (player **)NewHandleClear( sizeof( player ));
- pl2info = (player **)NewHandleClear( sizeof( player ));
-
- LoadImages();
- //splashScreen=GetPicture(5000);
-
-
- SetRect(&sourceRect,320,210,640,420);
- SetRect(&destRect,0,0,320,210);
-
- CopyPixels(sourceRect,destRect);
- SetupSound();
- updateScores(PlayerOneScore,PlayerTwoScore);
- UpdateHealth();
- GameOff();
- //splashScreen=GetPicture(5000);
-
- while (!gDone)
- {
- gotEvent = WaitNextEvent(everyEvent,&gTheEvent,sleep,mouseRgn);
- if (gotEvent)
- doEvent();
- SetPlayerState();
- SetDrawState();
- if(gameOn)
- {
- Redraw();
- IncreaseScore();
- PlayAsync(drawState);
- SetHealth(PlayerOneScore,PlayerTwoScore);
- }
- }
-
- DisposeHandle( (Handle) pl1info );
- DisposeHandle( (Handle) pl2info );
- DisposeSound();
-
- //ShowMenuBar();
- InitMac();
- }
-
- void doEvent(void)
- {
-
- switch (gTheEvent.what)
- {
- // case mouseDown:
- // DoMouseDown();
- // break;
- case keyDown:
- lastCharacter = gTheEvent.message & charCodeMask;
-
-
- if (splashOn)
- if ((lastCharacter == 'Q') || (lastCharacter == 'q'))
- if (gTheEvent.modifiers & cmdKey)
- gDone=true;
-
- if ((lastCharacter == 'Q') || (lastCharacter == 'q'))
- if (gTheEvent.modifiers & cmdKey)
- DrawPicture(splashScreen, &gdestrect);
- splashOn=true;
-
-
-
-
- if (lastCharacter == ' ')
- {
- if(gameOn)
- GameOff();
- else
- GameOn();
- }
- break;
- case osEvt:
-
- switch (gTheEvent.what )
- {
- case activateEvt:
- background = ( (gTheEvent.modifiers & activeFlag) != 0 );
- break;
- }
- break;
-
- }
- }
-
- void SetPlayerState(void)
- {
- long tick;
- KeyMap keyMap;
- int rand;
-
- tick=TickCount();
-
- if((playerOneUpdateTime+5)<tick)
- {
- playerOne.state=1;
- }
- if((playerTwoUpdateTime+5)<tick)
- {
- playerTwo.state=1;
- }
-
- if (((lastCharacter == 'D')||(lastCharacter=='d'))&&((playerOneUpdateTime+10)<tick))
- {
- playerOne.state=0;
- playerOneUpdateTime=tick;
- soundPlayed=false;
- lastCharacter = '~';
- }
-
- if (((lastCharacter == 'K')||(lastCharacter=='k'))&&((playerTwoUpdateTime+10)<tick))
- {
- playerTwoUpdateTime=tick;
- playerTwo.state=0;
-
- soundPlayed=false;
- lastCharacter = '~';
- }
-
- GetKeys(keyMap);
- if((keyMap[0] >> 16) & 0x01)
- playerOne.state=2;
- if((keyMap[1] >> 22) & 0x01)
- playerTwo.state=2;
-
- if(playerOne.state==0)
- if((keyMap[1] >> 16) & 0x01)
- {
- rand = (Random()%100);
- if (rand<50)
- playerOne.state=1;
- if (rand>50)
- playerTwo.state=1;
- }
-
- if(playerTwo.state==0)
- if((keyMap[0] >> 26) & 0x01)
- {
- rand = (Random()%100);
- if (rand<50)
- playerOne.state=1;
- if (rand>50)
- playerTwo.state=1;
- }
-
-
- SetDrawState();
-
- }
-
- void SetDrawState(void)
- {
- if((playerOne.state==0)&&(playerTwo.state==1))
- drawState=1;
- if((playerOne.state==0)&&(playerTwo.state==2))
- drawState=2;
- if((playerOne.state==1)&&(playerTwo.state==0))
- drawState=3;
- if((playerOne.state==1)&&(playerTwo.state==1))
- drawState=4;
- if((playerOne.state==1)&&(playerTwo.state==2))
- drawState=5;
- if((playerOne.state==2)&&(playerTwo.state==0))
- drawState=6;
- if((playerOne.state==2)&&(playerTwo.state==1))
- drawState=7;
- if((playerOne.state==2)&&(playerTwo.state==2))
- drawState=8;
- }
-
- void Redraw(void)
- {
- DrawBackground();
- DrawPlayers(drawState, soundPlayed);
- DrawFinal();
- lastRedraw=TickCount();
- }
-
- void InitMac (void)
- {
- InitGraf (&qd.thePort);
- InitFonts ();
- FlushEvents (everyEvent, 0);
- InitWindows ();
- InitMenus ();
- TEInit ();
- InitDialogs (0L);
- InitCursor ();
- MaxApplZone ();
-
- // HideCursor();
- HideMenuBar();
-
- }
-
- void WindowSetup (void)
- {
- Rect scoreWindowRect;
- Rect screenRect;
- Rect mainWindowRect;
- GDHandle hGD;
- PicHandle background;
- Rect backgroundRect;
-
- hGD=GetMainDevice();
- screenRect=((GDPtr)*hGD)->gdRect;
- SetRect(&mainWindowRect, (screenRect.right/2)-320, (screenRect.bottom/2)-240, (screenRect.right/2)+320, (screenRect.bottom/2)+240);
- SetRect(&backgroundRect,0,0,640,480);
-
- gScreenWindow = NewCWindow (0L, &screenRect, "\p ", true, plainDBox, (WindowPtr) - 1L, true, 0);
- PaintRect(&screenRect);
- background=GetPicture(600);
-
- gMainWindow = NewCWindow (0L, &mainWindowRect, "\p ", true, plainDBox, (WindowPtr) - 1L, true, 0);
- SetPort(gMainWindow);
- DrawPicture(background,&backgroundRect);
-
- SetRect (&gWindowTwoRect, mainWindowRect.left+62,mainWindowRect.top+107,mainWindowRect.left+382,mainWindowRect.top+317);
- gWindowTwo = NewCWindow (0L, &gWindowTwoRect, "\pThe Perfect Game. Well, a Game", true, plainDBox, (WindowPtr) - 1L, true, 0);
-
- }
-
- void IncreaseScore(void)
- {
- if (!(drawState==lastSoundPlayed))
- {
- switch (drawState)
- {
- case 1:
- PlayerOneScore++;
- break;
- case 2:
- break;
- case 3:
- PlayerTwoScore++;
- break;
- case 4:
- break;
- case 5:
- break;
- case 6:
- break;
- case 7:
- break;
- case 8:
- break;
- }
- updateScores(PlayerOneScore,PlayerTwoScore);
- }
- }
-
- void GameOff(void)
- {
- Rect destRect;
- PicHandle eyesPic;
-
- eyesPic=GetPicture(4711);
- SetRect(&destRect,0,0,320,240);
- SetPort(gWindowTwo);
- DrawPicture(eyesPic,&destRect);
- gameOn=false;
- }
-
- void GameOn(void)
- {
- gameOn=true;
- }
-
-